<template>
  <div>
    <!-- 现金流量表查询 -->
    <TopFilter ref="form" :list="topFilterList" :cols="3" @filterChange="changeHandle" @resetChange="resetChange" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="zjlCashFlowReportQuery"
        :isToperInfo="false"
        :isColumnFilter="false"
        :isSelectColumn="false"
        :columns="columns"
        :dataSource="checkList"
        :onColumnsChange="columns => (this.columns = columns)"
      >
      </FilterTable>
    </Spin>

    <!-- 经销商查询 -->
    <BaseDialog :visible.sync="isDealer" title="经销商查询" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <OwnerSearch :rowData="formData" @close="emitCloseHandler" />
    </BaseDialog>
        <!-- 详情展示 -->
    <Drawer :visible.sync="actionsOwner.visible" :title="actionsOwner.title" width="80%" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DetailView :formData="this.tableList" :viewStatus="this.passStatus" :requestId="this.reportId" :year="this.year" :month="this.month" @close="closeSetting" @refrish="refrishList"/>
    </Drawer>
  </div>
</template>
<script>
import moment from 'moment';
import { getOwnerCode } from '@/assets/js/auth';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils/index';
import { queryList, exportExcel, submitData } from '@/api/omFinance/CRReportManage/CashFlowReportQuery';
import OwnerSearch from '../OwnerSearch';
import DetailView from './detailView';
export default {
  name: 'CashFlowReportQuery',
  mixins: [dictionary],

  components: {
    OwnerSearch,
    DetailView
  },
  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '明细' };
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      formList: [],
      isDealer: false,
      isDisabled: true,
      exportLoading: false,
      formData: {},
      tableList: [],
      reportId: '',
      year: moment().format('YYYY'),
      month: moment().format('MM'),
      dealerCode: '',
      cellstyles: [],
      actionsOwner: { visible: false, title: '', type: '' },
      checkList: [],
      statusCode:'',
      passStatus:'',
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
      //刷新
  refrishList(){
    this.getList(this.year, this.month, this.dealerCode,this.statusCode);
  },
        //展示详情
    openHandler(data){
      this.passStatus = data.cashFlowStatus;
     this.reportId = data.id; // 导出传id
        this.tableList = [
            {
              column1: '编制单位:',
              column2: data.dealerCode,
              column3: data.dealerName,
              column4: '单位：元'
            },
            {
              column1: '项    目',
              column2: '行次',
              column3: '本月数',
              column4: '本年累计数'
            },
            {
              column1: '一、经营活动产生的现金流量：',
              column2: '',
              column3: '',
              column4: ''
            },
            {
              column1: '销售商品、提供劳务收到的现金',
              column2: '1',
              column3: data.bqxssptglwsddxj,
              column4: data.bnxssptglwsddxj
            },
            {
              column1: '收到的税费返还',
              column2: '2',
              column3: data.bqsddsffh,
              column4: data.bnsddsffh
            },
            {
              column1: '收到其他与经营活动有关的现金',
              column2: '3',
              column3: data.bqsdqtyjyhdxgdxj,
              column4: data.bnsdqtyjyhdxgdxj
            },
            {
              column1: '经营活动现金流入小计',
              column2: '4=1+2+3',
              column3: data.bqjyhdxjlrxj,
              column4: data.bnjyhdxjlrxj
            },
            {
              column1: '购买商品、接受劳务支付的现金',
              column2: '5',
              column3: data.bqgmspjslwzfdxj,
              column4: data.bngmspjslwzfdxj
            },
            {
              column1: '支付给职工以及为职工支付的现金',
              column2: '6',
              column3: data.bqzfgzgyjwzgzfdxj,
              column4: data.bnzfgzgyjwzgzfdxj
            },
            {
              column1: '支付的各项税费',
              column2: '7',
              column3: data.bqzfdgxsf,
              column4: data.bnzfdgxsf
            },
            {
              column1: '支付其他与经营活动有关的现金',
              column2: '8',
              column3: data.bqzfqtyjyhdxgdxj,
              column4: data.bnzfqtyjyhdxgdxj
            },
            {
              column1: '经营活动现金流出小计',
              column2: '9=5+6+7+8',
              column3: data.bqjyhdxjlcxj,
              column4: data.bnjyhdxjlcxj
            },
            {
              column1: '经营活动产生的现金流量净额',
              column2: '10=4-9',
              column3: data.bqjyhdcsdxjllje,
              column4: data.bnjyhdcsdxjllje
            },
            {
              column1: '二、投资活动产生的现金流量：',
              column2: '',
              column3: '',
              column4: ''
            },
            {
              column1: '收回投资收到的现金',
              column2: '11',
              column3: data.bqshtzsddxj,
              column4: data.bnshtzsddxj
            },
            {
              column1: '取得投资收益收到的现金',
              column2: '12',
              column3: data.bqqdtzsysddxj,
              column4: data.bnqdtzsysddxj
            },
            {
              column1: '处置固定资产、无形资产和其他长期资产收回的现金净额',
              column2: '13',
              column3: data.bqczgdzcwxzcdqtcqzcshdxjje,
              column4: data.bnczgdzcwxzchqtcqzcshdxjje
            },
            {
              column1: '处置子公司及其他营业单位收到的现金净额',
              column2: '14',
              column3: data.bqczzgsjqtyydwsddxjje,
              column4: data.bnczzgsjqtyydwsddxjje
            },
            {
              column1: '收到其他与投资活动有关的现金',
              column2: '15',
              column3: data.bqsdqtytzhdygdxj,
              column4: data.bnsdqtytzhdygdxj
            },
            {
              column1: '投资活动现金流入小计',
              column2: '16=11+12+13+14+15',
              column3: data.bqtzhdxjlrxj,
              column4: data.bntzhdxjlrxj
            },
            {
              column1: '购建固定资产、无形资产和其他长期资产支付的现金',
              column2: '17',
              column3: data.bqgjgdzcwxzchqtcqzczfdxj,
              column4: data.bngjgdzcwxzchqtcqzczfdxj
            },
            {
              column1: '投资支付的现金',
              column2: '18',
              column3: data.bqtzzfdxj,
              column4: data.bntzzfdxj
            },
            {
              column1: '取得子公司及其他营业单位支付的现金净额',
              column2: '19',
              column3: data.bqqdzgsjqtyydwzfdxjje,
              column4: data.bnqdzgsjqtyydwzfdxjje
            },
            {
              column1: '支付其他与投资活动有关的现金',
              column2: '20',
              column3: data.bqzfqtytzhdygdxj,
              column4: data.bnzfqtytzhdygdxj
            },
            {
              column1: '投资活动现金流出小计',
              column2: '21=17+18+19+20',
              column3: data.bqtzhdxjlcxj,
              column4: data.bntzhdxjlcxj
            },
            {
              column1: '投资活动产生的现金流量净额',
              column2: '22=16-21',
              column3: data.bqtzhdcsdxjllje,
              column4: data.bntzhdcsdxjllje
            },
            {
              column1: '三、筹资活动产生的现金流量：',
              column2: '',
              column3: '',
              column4: ''
            },
            {
              column1: '吸收投资收到的现金',
              column2: '23',
              column3: data.bqxstzsddxj,
              column4: data.bnxstzsddxj
            },
            {
              column1: '取得借款收到的现金',
              column2: '24',
              column3: data.bqxstzsddxj,
              column4: data.bnxstzsddxj
            },
            {
              column1: '收到其他与筹资活动有关的现金',
              column2: '25',
              column3: data.bqsdqtyczhdygdxj,
              column4: data.bnsdqtyczhdygdxj
            },
            {
              column1: '筹资活动现金流入小计',
              column2: '26=23+24+25',
              column3: data.bqczhdxjlrxj,
              column4: data.bnczhdxjlrxj
            },
            {
              column1: '偿还债务支付的现金',
              column2: '27',
              column3: data.bqchzwzfdxj,
              column4: data.bnchzwzfdxj
            },
            {
              column1: '分配股利、利润或偿付利息支付的现金',
              column2: '28',
              column3: data.bqfpgllrhcflxzfdxj,
              column4: data.bnfpgllrhcflxzfdxj
            },
            {
              column1: '支付其他与筹资活动有关的现金',
              column2: '29',
              column3: data.bqzfqtyczhdxgdxj,
              column4: data.bnzfqtyczhdxgdxj
            },
            {
              column1: '筹资活动现金流出小计',
              column2: '30=27+28+29',
              column3: data.bqczhdxjlcxj,
              column4: data.bnczhdxjlcxj
            },
            {
              column1: '筹资活动产生的现金流量净额',
              column2: '31=26-30',
              column3: data.bqczhdcsdxjllje,
              column4: data.bnczhdcsdxjllje
            },
            {
              column1: '四、汇率变动对现金及现金等价物的影响',
              column2: '32',
              column3: data.bqhlbddxjjxjdjwdyx,
              column4: data.bnhlbddxjjxjdjwdyx
            },
            {
              column1: '五、现金及现金等价物净增加额',
              column2: '33=10+22+31+32',
              column3: data.bqxjjxjdjwjzje,
              column4: data.bnxjjxjdjwjzje
            },
            {
              column1: '加：期初现金及现金等价物余额',
              column2: '34=资产负债表中行次1“货币资金”的期初余额',
              column3: data.bqqcxjjxjdjwye,
              column4: data.bnqcxjjxjdjwye
            },
            {
              column1: '六、期末现金及现金等价物余额',
              column2: '35=33+34=资产负债表中行次1“货币资金”的期末余额（校验）',
              column3: data.bqqmxjjxjdjwye,
              column4: data.bnqmxjjxjdjwye,
              checkStatus: data.checkStatus
            }
          ];
        
        this.actionsOwner = { visible: true, title: '编辑', type: 'show' };
    },
   closeSetting() {
        this.actionsOwner.visible = false;
    },
    syncTableData(data) {
      if (!data.length) return;
      data.forEach(x => {
        if (x.checkStatus == 10041002) {
          this.cellstyles.push({ row: x, dataIndex: 'column4', styles: { backgroundColor: 'red' } });
        }
      });
    },
    seacherFun() {
      this.isDealer = true;
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    changeHandle(params) {
      this.year = params.yearMonth.split('-')[0];
      this.month = params.yearMonth.split('-')[1];
      this.dealerCode = params.ownerCode;
      this.statusCode = params.cashFlowStatus;
      console.log(params);
      this.getList(this.year, this.month, this.dealerCode,this.statusCode);
     
    },
    resetChange(params) {
      this.year = params.yearMonth.split('-')[0];
      this.month = params.yearMonth.split('-')[1];

      // this.getList(this.year, this.month, '');
      this.tableList = [];
      
    },
    // 导入
    importHandle() {
      this.isImport = true;
    },
    emitCloseHandler(val, data) {
      this.isDealer = val;
      if (data) {
        let dealerCodes = [];
        let dealerNames = [];
        data.map(x => {
          dealerCodes.push(x.dealerCode);
          dealerNames.push(x.dealerName);
        });
        this.topFilterList.find(x => x.fieldName == 'ownerCode').initialValue = dealerCodes.toString();
        this.topFilterList.find(x => x.fieldName == 'dealerName').initialValue = dealerNames.toString();
      }
    },
    // 表单数据
    formChangeHandle(val) {
      this.saveData = Object.assign({}, this.saveData, val);
      console.log(val, this.saveData, '---奥利给---');
    },
    // 查询列表
    async getList(Year = '', Month = '', dealerCode = '',statusCode = '') {
      this.exportLoading = true;
      const res = await queryList({ reportYear: Year, reportMonth: Month, dealerCode: dealerCode ,cashFlowStatus:statusCode});
      this.reportId = '';
      this.tableList = [];
      if (res.resultCode == 200) {
        if (res.data) {
          this.isDisabled = false;
          const data = res.data; // 表格
          this.reportId = data.id; // 导出传id
          this.checkList = res.data;
        } else {
          this.isDisabled = true;
          this.tableList = [];
          // 驳回意见清空
          this.formList[0].rules[0].required = false;
          this.formList[0].initialValue = '';
        }
      }
      this.exportLoading = false;
    },
    // 导出
    async exportHandle() {
      await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        confirmButtonText: '下载',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.exportLoading = true;
          let param = { id: this.reportId };
          exportExcel(param)
            .then(response => {
              exportExcelFile(response.data, '现金流量表查询');
              this.exportLoading = false;
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },

    createdFrom() {
      return [
        {
          type: 'DATE',
          label: '月度',
          fieldName: 'yearMonth',
          dateType: 'month',
          initialValue: moment().format('YYYY-MM'),
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          placeholder: '请选择',
          rules: [{ required: false, message: '请选择', trigger: 'blur' }],
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },
        // {
        //   type: 'INPUT',
        //   label: '经销商名称',
        //   fieldName: 'dealerName',
        //   placeholder: '',
        //   disabled: true
        // },
        {
          type: 'SELECT',
          label: '审核状态',
          fieldName: 'cashFlowStatus',
          placeholder: '',
          itemList: this.createDictList('6080')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 70,
          render: props => {
            return (
              <div style="text-align:center">
                <el-button size="mini" type="text" onClick={() => this.openHandler(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
       {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '提报日期',
          dataIndex: 'reportDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '状态',
          dataIndex: 'cashFlowStatus',
          sorter: true,
          filter: true,
          filterType: 'input',
          filterItems: this.createDictList('6080'),
          render: props => {
            return <span>{this.createDictText(props.row.cashFlowStatus, '6080')}</span>;
          }
        },
        {
          title: '驳回原因',
          dataIndex: 'checkDesc',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
